using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SchemaMonitor;
using Framework;

partial class pages_Chapters_usercontrols_UCChaptersPair : UserControl
{    
    #region Members
    private CSection _section;
    private SchemaMonitor.CNode _node;
	#endregion



	#region Main Interface (Parent Entity)
	//Friendly Urls recommended for paging within tabs
	public void Display(CSection section, string searchStateFromQuerystring, string friendlyUrl, CUser u)
    {
        Display(section, searchStateFromQuerystring, u);
        this.FriendlyUrl = friendlyUrl;
    }
    public void Display(SchemaMonitor.CNode node, string searchStateFromQuerystring, string friendlyUrl)
    {
        Display(node, searchStateFromQuerystring);
        this.FriendlyUrl = friendlyUrl;
    }    
    
    //Simple Interface
    public void Display(CSection section, string searchStateFromQuerystring, CUser u)
    {
		CTextbox.OnReturnPress(txtSearch, btnSearch);

		_section = section;

        string searchStateFromForm = CWeb.RequestStr(txtSearch.UniqueID); //txtSearch - postback value still not set during Page_Init
		if (string.IsNullOrEmpty(searchStateFromQuerystring) || ! string.IsNullOrEmpty(searchStateFromForm))
		{
			searchStateFromQuerystring = searchStateFromForm;
			CSession.SearchChapters = searchStateFromQuerystring;
		}
		txtSearch.Text = searchStateFromQuerystring;

		if (Title.Length == 0) Title = "Posts";


		chk.Checked = CSession.ExcludeAll;
		if (Request["__EVENTTARGET"] == chk.UniqueID)
			chk.Checked = false;
		if (Request.Form[chk.UniqueID] != null)
			chk.Checked = true;
		CSession.ExcludeAll = chk.Checked;


		ctrlRemaining.DisplayRemaining(section, searchStateFromQuerystring, u, chk.Checked); 
        ctrlSelected.DisplaySelected(section, u);
    }
    public void Display(SchemaMonitor.CNode node, string searchStateFromQuerystring)
    {
        _node = node;

		string searchStateFromForm = CWeb.RequestStr(txtSearch.UniqueID); //txtSearch - postback value still not set during Page_Init
		if (string.IsNullOrEmpty(searchStateFromQuerystring))
		{
			searchStateFromQuerystring = searchStateFromForm;
			CSession.SearchChapters = searchStateFromQuerystring;
		}
		txtSearch.Text = searchStateFromQuerystring;


		if (Title.Length == 0) Title = "Sections";

		ctrlRemaining.DisplayRemaining(node, searchStateFromQuerystring);
        ctrlSelected.DisplaySelected(node);
    }  
    #endregion

    #region Event Handlers
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (null != _node)
            Response.Redirect(CSitemap.ChaptersForNode(_node.NodeGuid, txtSearch.Text)); //txtSearch - postback value still not set during Page_Init
        else
            Response.Redirect(CSitemap.ChaptersForSection(_section.SectionId, txtSearch.Text)); //txtSearch - postback value still not set during Page_Init
    }
    #endregion
    
    #region Appearance
    public string Title 
    {
        get { return ctrlRemaining.Title; }
        set 
        {
            ctrlRemaining.Title = value;
            ctrlSelected.Title = value;
        }
    }
    #endregion
    
    #region Behaviour
    #endregion
    
    #region Paging
    public string QueryString 
    {
        get { return ctrlRemaining.QueryString.Substring(0, ctrlRemaining.QueryString.Length - 1); }
        set 
        {
            ctrlRemaining.QueryString = value + "1";
            ctrlSelected.QueryString = value + "2";
        }
    }
    public int PageSize 
    {
        get { return ctrlRemaining.PageSize; }
        set 
        {
            ctrlRemaining.PageSize = value;
            ctrlSelected.PageSize = value;
        }
    }
    public string FriendlyUrl 
    {
        set 
        {
            ctrlRemaining.FriendlyUrl = value;
            ctrlSelected.FriendlyUrl = value;
        }
    }
    #endregion
    
}